<template>
  <vol-box
    :lazy="true"
    v-model="modelOpen"
    title="选择商品"
    :height="400"
    :width="1200"
    :padding="5"
    :onModelClose="onModelClose"
  >
    <goodsInventory ref="goodsInventory"></goodsInventory>
    <!--
         <el-form :inline="true" :model="form" class="demo-form-inline">
        <el-form-item label="库位名称:">
          <el-input
            v-model="form.goods_sub"
            placeholder="库位名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="商品名称:">
          <el-input
            v-model="form.goods_name"
            placeholder="商品名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit" class="submitBtn"
            >查询</el-button
          >
        </el-form-item>
      </el-form> 
      <el-table
        ref="purchaseApplicationLitsTable"
        :data="tableList"
        stripe
        style="width: 100%"
        :header-cell-style="{ background: `#f8f8f9`, color: `#616161` }"
        border
        height="500"
        @selection-change="handleSelectionChange2"
      >
        <el-table-column
          type="selection"
          width="55"
          :selectable="changeSelectable"
        >
        </el-table-column>
        <el-table-column prop="Goods_sub" label="商品库位" width="200">
        </el-table-column>
        <el-table-column prop="Goods_sub" label="商品编码" width="200">
        </el-table-column>
        <el-table-column prop="Goods_name" label="商品名称" width="170">
        </el-table-column>
        <el-table-column prop="Goods_price" label="单价" width="80">
        </el-table-column>
        <el-table-column prop="Goods_size" label="规格" width="120">
        </el-table-column>
        <el-table-column prop="Goods_num" label="商品库存数量" width="180">
        </el-table-column>
        <el-table-column prop="Goods_price" label="商品库存金额" width="180">
        </el-table-column>
      </el-table>
    -->
    <template #footer>
      <div>
        <el-button type="primary" size="small" @click="onSelect"
          >确定</el-button
        >
      </div>
    </template>
  </vol-box>
</template>

<script>
import VolBox from "@/components/basic/VolBox.vue";
import goodsInventory from "@/views/inventoryinfo/q_goods_inventory/q_goods_inventory.vue";
export default {
  components: {
    "vol-box": VolBox,
    goodsInventory,
  },
  data() {
    return {
      modelOpen: false,
      form: {
        goods_sub: "",
        goods_name: "",
      },
      tableList: [],
    };
  },
  methods: {
    async onModelClose() {
      await this.$refs.goodsInventory.$refs.grid.search();
    },
    open() {
      this.modelOpen = true;
    },
    onSelect() {
      let rowObj = this.$refs.goodsInventory.$refs.grid.getSelectRows();
      console.log("rowObj", rowObj);
      if (rowObj.length) {
        this.$emit("parentCall", ($parent) => {
          let detailRowData = $parent.$refs.detail.rowData;
          let num = 0;
          detailRowData.forEach((item) => {
            rowObj.forEach((o) => {
              if (o.Voucher_sub == item.Voucher_sub) num++;
            });
          });

          if (!num) {
            let newRowObj = rowObj.map((item) => {
              return {
                Stock_inList: item.ID,
                Goods_sub: item.goods_code,
                Goods_name: item.goods_name,
              };
            });
            this.$emit("parentCall", ($parent) => {
              $parent.$refs.detail.rowData.unshift(...newRowObj);
              this.onModelClose();
            });
            return (this.modelOpen = false);
          } else {
            this.$message.error("此出库单已包含");
          }
        });
      } else {
        return this.$message.error("请选择商品");
      }
    },
  },
};
</script>

<style scoped>
</style>